<html>
<body>

<?php
include '../../../wp-blog-header.php';
include_once("../../../analyticstracking.php");
//$site_home = get_bloginfo('wpurl');
$var = $_GET['id'];//
$var = pods_sanitize(decrypt($var,'1b2u3z4z5r6'));
$api = new PodAPI();
//the variable sent is of the form "dealname,pagename,link(image or title),externallink(of deal)"
// so first thing is to split these variables
list($deal_name, $page, $link, $extlink,$deal_id) = split("~" , $var);
//the new tracking pod would be given same name as the deal
//$pod_name = $deal_name;
?>

<!-- Start of Adohana Tracking Code -->
<script type ="text/javascript" src="http://bsrv.adohana.com/ohana/adohana.js?usr=b6f45651887c51850f8de7a031a17fa5"></script>
<!-- End of Adohana Tracking Code -->
<script type ="text/javascript">
addStringEvents('dealname','<?php echo $deal_name; ?>');
addStringEvents('dealtype', 'Online Offer');
trackEvent(61);
</script>

<?php
$where = "campaign.id='".$deal_id."'";
$Record = new Pod('tracking');
$Record->findRecords('name ASC',1,$where);
$total_rows = $Record->getTotalRows();

while($Record->fetchRecord())
{
$tracking_id = $Record->get_field('id');
$pageviews_tracking = $Record->get_field('pageviews');
}

/*Checks if user is Admin, if yes does not allow update*/
global $current_user;
get_currentuserinfo();
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
if ($user_role != 'administrator')
{
/*Checks if user is Admin, if yes does not allow update*/

if($total_rows > 0)
{
  switch($page)
  {
  case "listpage":
      switch($link)
      {
        case "image":
          $views = pod_query("UPDATE wp_pod_tbl_tracking SET wp_pod_tbl_tracking.listpage_image=wp_pod_tbl_tracking.listpage_image+1 WHERE wp_pod_tbl_tracking.id ='$tracking_id'");
        break;
        case "title":
          $views = pod_query("UPDATE wp_pod_tbl_tracking SET wp_pod_tbl_tracking.listpage_title=wp_pod_tbl_tracking.listpage_title+1 WHERE wp_pod_tbl_tracking.id ='$tracking_id'");
        break;
      }
  break;
  
  case "detailpage":
      switch($link)
      {
        case "image":
          $views = pod_query("UPDATE wp_pod_tbl_tracking SET wp_pod_tbl_tracking.detailpage_image=wp_pod_tbl_tracking.detailpage_image+1 WHERE wp_pod_tbl_tracking.id ='$tracking_id'");
        break;
        case "title":
          $views = pod_query("UPDATE wp_pod_tbl_tracking SET wp_pod_tbl_tracking.detailpage_title=wp_pod_tbl_tracking.detailpage_title+1 WHERE wp_pod_tbl_tracking.id ='$tracking_id'");
        break;
        case "grab_button":
          $views = pod_query("UPDATE wp_pod_tbl_tracking SET wp_pod_tbl_tracking.detailpage_grab_button=wp_pod_tbl_tracking.detailpage_grab_button+1 WHERE wp_pod_tbl_tracking.id ='$tracking_id'");
        break;
      }
  break;
  }
}

}
/*Closed loop Checks if user is Admin, if yes does not allow update*/

if( $extlink != Null)
{
?>
 <script type="text/javascript">window.location="http://<?php echo $extlink; ?>";</script>
<?php
}
/* If the variable external link is null then go to same screen */
else
{
echo '<script type=""text/javascript"">history.go(-1);</script>';
}
?>
</body>
</html>